﻿using Microsoft.AspNetCore.Mvc;
using ProductService.Services;
using ProductService.Services.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace ProductService.Controllers;

[Route("api/productservice/[action]")]
public class ProductController : AbpController, IProductService
{
    public IProductService ProductService { get; set; }

    public ProductController()
    {

    }

    [HttpPost]
    public async Task<ProductDto> CreateAsync(ProductDto input)
    {
        // 1、生成Token   Demo
        //var result = await _clientService.AuthenticateWithPasswordAsync(new OpenIddictClientModels.PasswordAuthenticationRequest
        //{
        //    Issuer = new Uri("https://localhost:7047"),
        //    Username = "Akira",
        //    Password = "Admin123!",
        //    Scopes = new List<string> { "manger2" },
        //});

        return await ProductService.CreateAsync(input);
    }

    [HttpDelete]
    public async Task DeleteAsync(Guid id)
    {
        await ProductService.DeleteAsync(id);
    }

    [HttpGet]
    public async Task<ProductDto> GetAsync(Guid id)
    {
        return await ProductService.GetAsync(id);
    }

    [HttpPost]
    public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
    {
        return await ProductService.GetListAsync(input);
    }

    [HttpPut]
    public async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
    {
        return await ProductService.UpdateAsync(id, input);
    }
}
